/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY. 
 * See the GNU General Public License for more details.
 * 
 * Copyright (C) 2011 CellObject.net
 */
package net.cellobject.javacodeformatter.editor;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

/**
 * A label provider maps an element of the viewer's model to an optional image and optional text string used to display the
 * element in the viewer's control. In our case, this label provider extracts text from the {@link PropertyElement} to display in
 * the editor.
 */
public class PropertyEditorLabelProvider extends LabelProvider implements ITableLabelProvider {
	public Image getColumnImage(final Object element, final int columnIndex) {
		return null;
	}

	public String getColumnText(final Object element, final int columnIndex) {
		if (element instanceof PropertyCategory) {
			final PropertyCategory category = (PropertyCategory)element;
			switch (columnIndex) {
				case 0:
					return category.getName();
				case 1:
					return "";
			}
		}
		if (element instanceof PropertyEntry) {
			final PropertyEntry entry = (PropertyEntry)element;
			switch (columnIndex) {
				case 0:
					return entry.getKey();
				case 1:
					return entry.getValue();
			}
		}
		if (element == null) {
			return "<null>";
		}
		return element.toString();
	}
}
